<template>
  <view class="wanl-success">
    <!-- 导航条 -->
    <view class="cu-custom" :style="{ height: $wanlshop.wanlsys().height + 'px' }">
      <view
          class="cu-bar bg-bgcolor fixed"
          :style="{
					height: $wanlshop.wanlsys().height + 'px',
					paddingTop: $wanlshop.wanlsys().top + 'px'
				}"
      >
        <view class="action" @tap="onBackUser"><text class="wlIcon-fanhui1"></text></view>
        <view class="content" :style="{ top: $wanlshop.wanlsys().top + 'px' }">
          <text>{{ title }}完成</text>
        </view>
      </view>
    </view>

    <view class="content">
      <text class="icon wlIcon-pintuantuangouchenggong"></text>
      <text class="text-lg margin-tb">{{ title }}已成功</text>
      <view class="button padding-xl margin-top-lg">
        <button
            class="cu-btn block wanl-bg-orange margin-tb-sm lg"
            v-if="type == 'comment'"
            @tap="$wanlshop.to('/pages/user/comment/comment')"
        >
          查看评论
        </button>
        <!--				<button-->
        <!--					v-if="type == 'pay'"-->
        <!--					class="cu-btn block wanl-bg-orange margin-tb-sm lg"-->
        <!--					@tap="$wanlshop.on('/pages/user')"-->
        <!--				>-->
        <!--					用户中心-->
        <!--				</button>-->
        <button
            v-if="type == 'pay'"
            class="cu-btn block wanl-bg-orange margin-tb-sm lg"
            @tap="queren()"
        >
          确认
        </button>
        <button
            class="cu-btn block wanl-bg-orange margin-tb-sm lg"
            v-if="type == 'feedback'"
            @tap="$wanlshop.to('/pages/user/feedback/lists')"
        >
          查看反馈
        </button>
        <button
            class="cu-btn block wanl-bg-orange margin-tb-sm lg"
            v-if="type == 'complaint'"
            @tap="$wanlshop.to('/pages/user/complaint/lists')"
        >
          查看举报
        </button>
        <button
            class="cu-btn block wanl-bg-orange margin-tb-sm lg"
            v-if="type == 'withdraw'"
            @tap="$wanlshop.to('/pages/user/money/witlist')"
        >
          查看提现列表
        </button>
        <button
            class="cu-btn block bg-red margin-tb-sm lg"
            v-if="type == 'find'"
            @tap="$wanlshop.to('/pages/apps/find/user')"
        >
          查看创作中心
        </button>
        <button
            class="cu-btn block wanl-bg-orange margin-tb-sm lg"
            v-if="type == 'recharge'"
            @tap="$wanlshop.to('/pages/user/money/money')"
        >
          查看钱包
        </button>
        <button class="cu-btn block line-gray margin-tb-sm lg" @tap="onIndex">
          返回首页
        </button>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      type: '',
      title: '',
      order_no:'',
      code:'',
    };
  },
  created() {
    uni.login({
      success: (res) => {
        this.code = res.code;
		console.log(res,"created");
		console.log(this.code,"created");
      }
    })
  },
  onLoad(options) {
    if (options.order_no){
      this.order_no = options.order_no
      uni.login({
        provider: 'weixin', //使用微信登录
        success: function(loginRes) {
          // loginRes.code
        }
      });
    }

    if (options.type == 'pay') {
      this.title = '支付';
    } else if (options.type == 'comment') {
      this.title = '评论';
    } else if (options.type == 'feedback') {
      this.title = '反馈';
    } else if (options.type == 'withdraw') {
      this.title = '请等待后台审核，提交';
    } else if (options.type == 'recharge') {
      this.title = '充值';
    } else if (options.type == 'complaint') {
      this.title = '举报';
    } else if (options.type == 'find') {
      this.title = '作品上传';
    }
    this.type = options.type;
    // this.order_no = options.order_no
	if (options.order_no){
	  this.order_no = options.order_no;
	  uni.getStorageInfoSync("order_no");
	}
    console.log(options)
    // if (options.type === 'pay' && options.order_type === 'goods'){
	// this.transformation();
      // var clickID = ''
      // if (uni.getStorageSync('clickid')){
      //   // 巨量
      //   clickID = uni.getStorageSync('clickid')
      // }
      // if (uni.getStorageSync('bxmid')){
      //   // 变现猫
      //   clickID = uni.getStorageSync('bxmid')
      // }
      // if (uni.getStorageSync('qz_gdt')){
      //   // 腾讯
      //   clickID = uni.getStorageSync('qz_gdt')
      // }
      // if (uni.getStorageSync('cili')){
      //   // 磁力
      //   clickID = uni.getStorageSync('cili')
      // }
      // uni.request({
      //   url: '/wanlshop/common/zhuanhua',
      //   method: 'POST',
      //   data:{
      //     clickid:clickID,
      //     event_type:uni.getStorageSync('event_type'),
      //     type:true
      //   },
      //   success: res => {
      //     console.log("++++++++++++++++++++++++++++++++")
      //     console.log(res.data)
      //     if (res.data){
      //       // 商品支付成功后调用
      //       if (uni.getStorageSync('clickid')){
      //         this.sendtoTaq();
      //       }
      //       if (uni.getStorageSync('bxmid')){
      //         this.sendtoTaqbxm();
      //       }
      //       if (uni.getStorageSync('qz_gdt')){
      //         this.sendtoQzGdt()
      //       }
      //       if (uni.getStorageSync('cili')){
      //         this.sendtoCiLi()
      //       }
      //     }else{
      //       uni.removeStorageSync('bxmid')
      //       uni.removeStorageSync('clickid')
      //       uni.removeStorageSync('qz_gdt')
      //       uni.removeStorageSync('cili')
      //       uni.removeStorageSync('host')
      //       uni.removeStorageSync('event_type')
      //     }
      //   }
      // });
    // }
  },
  methods: {
    requestSubscription(userCode) {

      uni.requestSubscribeMessage({
        tmplIds: [this.$wanlshop.config('tmplIds')], // Replace with your actual template ID
        success: (res) => {
          console.log("订阅请求成功", res);
          this.sendMessage(this.order_no,userCode)
          // 订阅成功后的重定向或其他操作
        },
        fail: (res) => {
          console.log("订阅请求失败", res);
          // 处理订阅失败，例如向用户显示错误消息
        }
      });
    },
    queren(){
      // this.requestSubscription(this.code);
      this.$wanlshop.on('/pages/user/order/order');
    },
    async sendMessage(order_no,userCode){
      await uni.request({
        url: '/wanlshop/common/send_subscribe_message',
        method: 'POST',
        data: {
          order_no:order_no,
          code:userCode,
          appid:this.$wanlshop.config('miniappid'),
          tmplIds: this.$wanlshop.config('tmplIds'),
        },
        success: res => {
          console.log('请求模板消息',res);
        }
      })
    },
    onIndex() {
      if (this.code){
        this.requestSubscription(this.code);
      }
      uni.setTabBarStyle({
        backgroundColor: '#ffffff',
        borderStyle: 'white'
      });
      uni.switchTab({
        url: '/pages/index'
      });
    },
    onBackUser() {
      uni.setTabBarStyle({
        backgroundColor: '#ffffff',
        borderStyle: 'white'
      });
      uni.switchTab({
        url: '/pages/user'
      });
    },
   //  sendtoTaq:function (clickid) {
   //    console.log(clickid);
	  // console.log(clickid,'进来了？')
   //    var self = this;
   //    uni.request({
   //      method:'POST',
   //      url: 'https://analytics.oceanengine.com/api/v2/conversion',
   //      header: {},
   //      data: {
   //        "event_type": uni.getStorageSync('event_type'),
   //        "context": {
   //          "ad": {
   //            "callback": uni.getStorageSync('clickid'),//callback 这里需要填写的就是从启动参数里获取的 clickid
   //          }
   //        },
   //        "timestamp": new Date().getTime()
   //      },
   //      success: function(res) {
   //        console.log('++++++++++ success   ++++++++++++++++')
   //        console.log(JSON.stringify(res.data))
   //        uni.removeStorageSync('clickid')
   //        uni.removeStorageSync('event_type')
   //      },
   //      error: function(err) {
   //        console.log('++++++++++ error   ++++++++++++++++')
   //        console.log(JSON.stringify(err))
   //      },
   //      finally: function(res) {
   //        console.log('++++++++++ finally   ++++++++++++++++')
   //      }
   //    })
   //  },
   transformation() {
   	var self = this
   	var clickID = ''
   	if (uni.getStorageSync('clickid')) {
   		// 巨量
   		clickID = uni.getStorageSync('clickid')
   	}
   	if (uni.getStorageSync('bxmid')) {
   		// 变现猫
   		clickID = uni.getStorageSync('bxmid')
   	}
   	if (uni.getStorageSync('qz_gdt')) {
   		// 腾讯
   		clickID = uni.getStorageSync('qz_gdt')
   	}
   	if (uni.getStorageSync('cili')) {
   		// 磁力
   		clickID = uni.getStorageSync('cili')
   	}
   	uni.request({
   		url: '/wanlshop/common/zhuanhua',
   		method: 'POST',
   		data: {
   			clickid: clickID,
   			event_type: uni.getStorageSync('event_type'),
   			type: true
   		},
   		success: res => {
   			console.log("++++++++++++++++++++++++++++++++")
   			console.log(res.data)
   			if (res.data) {
   				// 商品支付成功后调用
   				if (uni.getStorageSync('clickid')) {
   					this.sendtoTaq();
   				}
   				if (uni.getStorageSync('bxmid')) {
   					this.sendtoTaqbxm();
   				}
   				if (uni.getStorageSync('qz_gdt')) {
   					this.sendtoQzGdt()
   				}
   				if (uni.getStorageSync('cili')) {
   					this.sendtoCiLi()
   				}
   			} else {
   				uni.removeStorageSync('bxmid')
   				uni.removeStorageSync('clickid')
   				uni.removeStorageSync('qz_gdt')
   				uni.removeStorageSync('cili')
   				uni.removeStorageSync('host')
   				uni.removeStorageSync('event_type')
   			}
   		}
   	});
   },
   sendtoTaq: function(clickid) {
   	console.log(clickid);
   	var self = this;
   	uni.request({
   		method: 'POST',
   		url: '/index/req',
   		header: {},
   		data: {
   			"event_type": uni.getStorageSync('event_type'),
   			"clickid": uni.getStorageSync('clickid'),
   		},
   		success: function(res) {
   			console.log('++++++++++ success   ++++++++++++++++')
   			console.log(JSON.stringify(res.data))
   			uni.removeStorageSync('clickid')
   			uni.removeStorageSync('event_type')
   		},
   		error: function(err) {
   			console.log('++++++++++ error   ++++++++++++++++')
   			console.log(JSON.stringify(err))
   		},
   		finally: function(res) {
   			console.log('++++++++++ finally   ++++++++++++++++')
   		}
   	})
   },
    sendtoQzGdt:function () {
      var self = this;
      uni.request({
        method:'GET',
        url: 'https://tracking.e.qq.com/conv/web',
        header: {},
        data: {
          "clickid": uni.getStorageSync('qz_gdt'),
          "action_time": Math.floor(new Date().getTime() / 1000),
          "action_type": uni.getStorageSync('event_type'),
          "link": encodeURI(uni.getStorageSync('host')),
        },
        success: function(res) {
          console.log('++++++++++ success   ++++++++++++++++')
          console.log(JSON.stringify(res.data))
          uni.removeStorageSync('qz_gdt')
          uni.removeStorageSync('host')
          uni.removeStorageSync('event_type')
        },
        error: function(err) {
          console.log('++++++++++ error   ++++++++++++++++')
          console.log(JSON.stringify(err))
        },
        finally: function(res) {
          console.log('++++++++++ finally   ++++++++++++++++')
        }
      })
    },
    sendtoCiLi:function () {
      var self = this;
      uni.request({
        method:'GET',
        url: 'https://ad.partner.gifshow.com/track/activate',
        header: {},
        data: {
          "callback": uni.getStorageSync('cili'),
          "event_time": new Date().getTime(),
          "event_type": uni.getStorageSync('event_type'),
          "purchase_amount": uni.getStorageSync('purchase_amount'),
        },
        success: function(res) {
          console.log('++++++++++ success   ++++++++++++++++')
          console.log(JSON.stringify(res.data))
          uni.removeStorageSync('cili')
          uni.removeStorageSync('event_type')
          uni.removeStorageSync('purchase_amount')
        },
        error: function(err) {
          console.log('++++++++++ error   ++++++++++++++++')
          console.log(JSON.stringify(err))
        },
        finally: function(res) {
          console.log('++++++++++ finally   ++++++++++++++++')
        }
      })
    },
    sendtoTaqbxm:function () {
      uni.request({
        method:'GET',
        url: 'https://openlog.bianxianmao.com/inads/s.gif',
        header: {},
        data: {
          mt:8,
          bxmid:uni.getStorageSync('bxmid'),
          conversion_type:uni.getStorageSync('event_type'),
        },
        success: function(res) {
          console.log('++++++++++ success   ++++++++++++++++')
          console.log(JSON.stringify(res.data))
          uni.removeStorageSync('bxmid')
          uni.removeStorageSync('event_type')
        },
        error: function(err) {
          console.log('++++++++++ error   ++++++++++++++++')
          console.log(JSON.stringify(err))
        },
        finally: function(res) {
          console.log('++++++++++ finally   ++++++++++++++++')
        }
      })
    },
  }
};
</script>

<style>
.wanl-success .content {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

.wanl-success .content .icon {
  font-size: 180rpx;
  color: #3aa112;
  margin-top: 150rpx;
}
.wanl-success .content .button {
  width: 100%;
}
</style>
